<!DOCTYPE html>
<html>
<head>
	<title>NexHome</title>
    
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	
    <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

    <!-- libraries -->
   <link href="css/lib/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
        <link href="css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
	<link rel="stylesheet" href="css/bootstrap-table.css"> 
    <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/index.css" type="text/css" media="screen" /> 
	   

    <!-- open sans font -->
    <link href='css/OpenSans.css' rel='stylesheet' type='text/css' />

    <!-- lato font -->
    <link href='css/Lato.css' rel='stylesheet' type='text/css' />
	
<!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]--> 
	 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Cache" content="no-cache">
<style>
	a{cursor:pointer}
	.fixed-table-pagination .pagination a {
padding: 9.5px 12px;
}
	</style>
</head>
<body>



	<!-- main container -->
    <div class="content">       
        <div class="container-fluid">
         <div id="pad-wrapper" class="users-list">

               <div class="row-fluid header">
                    <h3>设备管理&nbsp;&nbsp;&nbsp;<a id="ViewAllbtn"><i class="icon-refresh"></i></a></h3>
                    <div class="span10 pull-right">
                        <input type="text" class="span5" style="margin: 0;padding: 2px 6px;" id="SearchUserTxt" placeholder="输入设备SN或NID" onKeyDown="return entersearch(event);" />
						<a id="cleanBtn" onClick="cleanIput()" style="position: relative; margin:-25px -25px;color: #9ba8b6"><i class="icon-search"></i></a>

						&nbsp;
						<div class="ui-dropdown" style="margin: 0px 31px">
                            <div class="head" data-toggle="tooltip" title="Click me!" id="SearchUserbtn">
                                设备筛选
                                
                            </div>  
                            
                               
                        </div>
						<a class="btn-flat danger pull-right" id="sub_btnDelete" style="display:none;float:right; margin-left:10px;"><i class="icon-remove"></i>删除设备</a>&nbsp;&nbsp;
                        <a id="sub_btnAdd" class="btn-flat success pull-right" style="display:none">
                            <span>&#43;</span>
                            添加设备
                        </a>
						
                    </div>
					 
                    
                </div>
				 <!-- upper main stats -->
            <div id="devuser-stats"  style="display:none">
                <div class="row-fluid stats-row" >
                   <div >
							<table><tr><td><img src="img/contact-profile.png" class="avatar img-circle" /></td><td><h3 class="name" >当前工程商用户名：<span id="currorgname">测试系统</span></h3>
							<span class="area">当前工程商ID：&nbsp;&nbsp;</span><span class="area" id="currorgid">当前工程商ID:</span></td></tr></table>
							
					 </div>
                </div>
            </div>
            <!-- end upper main stats -->
				<div class="table-wrapper table-products" style="margin-top:70px;">
					
					 <div class="row-fluid table">
						<table id="table-sublist" class="table table-hover table-striped"></table>
					</div>
				 </div>
				
				 <div class="table-wrapper" style=" margin-bottom::10px;">
					
					
				 </div>
				
				
            </div>
        </div>
    </div>

<div class="modal small hide fade" id="devAddModal" tabindex="-1" role="dialog" aria-labelledby="devAddModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">添加设备</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
					<table>						
						<tr><td>输入设备SN</td><td><input type="text" id="addDevStart" name="addDevStart" class="input-xlarge" ></td></tr>
						<tr><td>输入备注</td><td><input type="text" id="addDevend" name="addDevend" class="input-xlarge" ></td></tr>
					</table>         			
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="devAddModal_addbtn">添加</button>
				</div>
</div>
<div class="modal small hide fade" id="devDeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">删除子设备</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>将删除全部已选子设备，是否确认删除？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="devAddModal_delbtn">删除</button>
				</div>
</div>	
<div class="modal small hide fade" id="DelOneUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">删除账户</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>将删除该账户，是否确认删除？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="DelOneUserModal_delbtn">删除</button>
				</div>
	</div>
	<div class="modal small hide fade" id="lockCfgModal" tabindex="-1" role="dialog" aria-labelledby="lockCfgModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="lockCfgModalLabel">配置锁定操作</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>是否将当前设备的配置进行锁定？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="lockCfg_btn">确定</button>
				</div>
</div> 
<div class="modal small hide fade" id="unlockCfgModal" tabindex="-1" role="dialog" aria-labelledby="unlockCfgModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="unlockCfgModalLabel">配置解锁操作</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>是否将当前设备的配置进行解锁？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="unlockCfg_btn">确定</button>
				</div>
</div> 
	<!-- scripts -->
	<script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery-latest.js"></script>
    <script src="js/bootstrap.min.js"></script>
		<script src="js/table/bootstrap-table.js"></script>
<script src="js/table/bootstrap-table-zh-CN.js"></script>
    <script src="js/jquery-ui-1.10.2.custom.min.js"></script>  
    <script src="js/theme.js"></script>
	<script src="js/bootbox.min.js"></script>
	
    <script type="text/javascript">
	var DevModifyInfo;
	var Modname = "";
	var Modmsk = '1';
	var CurrorgAccount = '';
	var sKeyVal = '';
	var currid='';
	//var currid=parent.CurrorgID;
	var isglobal = false;
	var globalControl = {
		isglobal: false,
		tableUrl: '',
		serachUrl: ''
	};
function request()
{ 
	var url = location.href;
	var paraString;
	if(url.indexOf("username") != -1){ 
 	paraString = url.substring(url.indexOf("=")+1,url.length);	 
	}
	else{
	paraString = "NO";
	}
	return paraString;  	
	
}
function DelOneUserDiv(oneUser)
{
	
	$('#DelOneUserModal').modal('show');
	$("#DelOneUserModal_delbtn").attr("onclick","DelOneUser(\'"+ oneUser +"\')");
	  	 
}
function DelOneUser(oneUser)
{
	
	 $.ajax({  
               
                url: '../adminMgr/device/removeDevice', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{devId: oneUser,orgId: currid},
				error : function() {
				
				 bootbox.alert("删除账户数据异常", function() {					
							//return;
						});
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){					
						$('#DelOneUserModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#DelOneUserModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table-sublist').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}               
								   
     })  
}
function InitTable(cururl)
{
	$('#table-sublist').bootstrapTable({
	method: 'get',
	url: cururl,	
	striped: true,
	dataType: "json",
	cache: false,
	pagination: true,
	"queryParamsType": "limit",
	singleSelect: false,
	contentType: "application/x-www-form-urlencoded",
	pageSize: 10,
	pageNumber:1,
	showRefresh: false,
	showToggle: false,	
	search: false, //不显示 搜索框
	showColumns: false, //不显示下拉框（选择显示的列）
	sidePagination: "server", //服务端请求
	queryParams: sublistqueryParams,
	responseHandler: sublistresponseHandler,
	columns: [
		{
			field: 'state',
			checkbox: true
         }, 	
		{
			field: 'id',	
			title: 'ID',	
			width: '5%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'sn',	
			title: 'SN',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'nid',	
			title: 'NID',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'online',	
			title: '在线状态',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
			formatter: onlineFormatter,
			sortable: false	
		},
		{
			field: 'remark',	
			title: '说明',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',
				
			sortable: false	
		},
		{
			field: 'orgName',	
			title: '所属工程商',	
			width: '10%',	
			align: 'center',	
			valign: 'middle',
				
			sortable: false	
		},		
		{
			title: '配置锁定',
			field: 'lockCfg',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			formatter: getlockCfgFormatter,				
			sortable: false	
		},
		{
			title: '删除设备',
			field: 'operate',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			formatter: operateFormatter,				
			sortable: false	
		}
	],
	onLoadSuccess:function(){

                },
	onLoadError: function () {
		alert("数据加载失败！");
	}
});
}
	$(function () {
	var username = request();
	if(username != 'NO'){ 	
		currid=parent.CurrorgID;
		
		$('#currorgname').html(decodeURIComponent(username));
		$('#currorgid').html(currid);
		globalControl.isglobal = false;
		globalControl.tableUrl = '../adminMgr/device/loadDeviceList';
		globalControl.serachUrl = '';
		InitTable(globalControl.tableUrl);
		$('#devuser-stats').show();
		$('#sub_btnDelete').show();
		$('#sub_btnAdd').show();
	}
	else{
		/*bootbox.alert("请从‘工程商管理’的工程商信息列表中选择工程商点击跳入", function() {					
						parent.Reload_orgList();
		});	*/
		currid='';
		globalControl.isglobal = true;
		globalControl.tableUrl = '../adminMgr/device/loadDeviceList';
		globalControl.serachUrl = '';
		$('#devuser-stats').hide();
		$('#sub_btnDelete').hide();
		$('#sub_btnAdd').hide();
		InitTable(globalControl.tableUrl);
	}
	
$('#ViewAllbtn').click(function(e){
		e.preventDefault();
		$('#table-sublist').bootstrapTable('refresh',{url:globalControl.tableUrl});
		
});
$('#SearchUserbtn').click(function (e) {
	sKeyVal = $("#SearchUserTxt").val();	
		/*要更改bootstrapTable的url*/
	$('#table-sublist').bootstrapTable('refresh',{url:'../adminMgr/device/loadDeviceList'});	              
});
$("#SearchUserTxt").focus(function(){
  $("#SearchUserTxt").val("");
});
$('#sub_btnAdd').click(function (e) {
	 e.preventDefault();
	$("#addDevStart").val("");
	$("#addDevend").val("");
	 $('#devAddModal').modal('show');               
 });

$('#sub_btnDelete').click(function (e) {
	 e.preventDefault();
	 $('#devDeleteModal').modal('show');               
 });

 $('#devAddModal_addbtn').click(function (e) {
	var start = $("#addDevStart").val();
	var end = $("#addDevend").val();

	 $.ajax({  
               
                url: '../adminMgr/device/addDevice', 
                type: 'post',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{orgId: currid,
					  sn: start,
					  remark: end},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){					
						$('#devAddModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#devAddModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table-sublist').bootstrapTable('refresh');
						});		
					 	
					 }
					 
				}
				   
     })  
	              
});
$('#devAddModal_delbtn').click(function (e) {
	
	var ids = "";
	var rows = $('#table-sublist').bootstrapTable('getSelections');
	for (var i = 0; i < rows.length; i++) {
		ids += rows[i].id + ',';
	}
	ids = ids.substring(0, ids.length - 1);
   
	if (ids == "") {
		alert("请选择您要删除的记录！");
		return;
	}	
	 $.ajax({  
               
                url: '../adminMgr/device/removeDevice', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{orgId: currid,devId: ids},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){					
						$('#devDeleteModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#devDeleteModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table-sublist').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}
				   
     })  
	              
});	
$('.fixed-table-header').empty();
});
	function sublistresponseHandler(res) {
	return {
	"rows": res.data.rows,
	"total": res.data.total
	};

}
function sublistqueryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
		sKey: sKeyVal,
		orgId: currid
	};
}


function getReaseFormatter(value, row, index) {
	return '<button class="btn-flat danger" data-toggle="button" onclick="GetReaseFrom('+row.id+ ','+index+')">解绑</button>';
}
function getLicenseFormatter(value, row, index) {
	return '<button class="btn-glow success" data-toggle="button" onclick="GetLicenseFrom('+row.id+ ','+index+')">激活</button>';
}
function getorgidFormatter(value, row, index) {
	return currid;
}
function GetLicenseFrom(pramidl,pramfrozenl)
{
	alert("1111");
	//alert(pramfrozen);
	//return;
}
function GetReaseFrom(pramid,pramfrozen)
{
	alert("222");
	//alert(pramfrozen);
	//return;
}
function getlockCfgFormatter(value, row, index) {
	if(row.lockCfg)
	return ['<button class="btn-flat danger" data-toggle="button" onclick="UnlockCfgDiv('+row.id+')">解锁</button>'].join('');
	else
	return ['<button class="btn-flat success" data-toggle="button" onclick="LockCfgDiv('+row.id+')">锁定</button>'].join('');
}
function operateFormatter(value, row, index) {
            return [/*'<a target="mainIframe" title="点击跳转到该设备的设备管理页" onclick="JumpTOOAMPage(\''+ row.sn+'\')"><i class="icon-pencil"></i></a>',*/
					'<a onclick="DelOneUserDiv(\''+ row.id+'\')" role="button" data-toggle="modal"><i class="table-delete"></i></a>'
                    ].join('');
}
function onlineFormatter(value, row, index) {
	if(row.online)
            return ['<i class="icon-user" style="color:#0088cc"></i>'
                    ].join('');
	else
		return ['<i class="icon-user"></i>'
                    ].join('');
}
function entersearch(event) {
	if (event.keyCode == 13) {
	sKeyVal = $("#SearchUserTxt").val();	
	//$("#SearchUserTxt").blur();
		/*要更改bootstrapTable的url*/
	$('#table-sublist').bootstrapTable('refresh',{url:'../adminMgr/device/loadDeviceList'});	
	}
}
function LockCfgDiv(curDevid)
{
	
	$('#lockCfgModal').modal('show');
	$("#lockCfg_btn").attr("onclick","lockCfg(\'"+ curDevid +"\')");
	 	 
}
function lockCfg(devId)
{
	$.ajax({  
               
                url: '../adminMgr/device/lockCfg', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{devId:devId},
				error : function() {
				
				 bootbox.alert("锁定配置数据异常", function() {					
							//return;
						});
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){											
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 bootbox.alert(deldata.resultMsg, function() {												
							
                            $('#table-sublist').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}               
								   
     })  
	 	 
}
function UnlockCfgDiv(curDevid)
{
	
	$('#unlockCfgModal').modal('show');
	$("#unlockCfg_btn").attr("onclick","lockCfg(\'"+ curDevid +"\')");
	 	 
}
function unlockCfg(devId)
{
	$.ajax({  
               
                url: '../adminMgr/device/lockCfg', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{devId:devId},
				error : function() {
				
				 bootbox.alert("锁定配置数据异常", function() {					
							//return;
						});
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){											
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 bootbox.alert(deldata.resultMsg, function() {												
							
                            $('#table-sublist').bootstrapTable('refresh');
						});
					 }
				}
     })
}
	/*监听键盘事件*/
	$("#SearchUserTxt").keyup(function(){
		var searchKey = $("#SearchUserTxt").val();
		if(searchKey){
			$("#cleanBtn > i").attr("class","icon-remove");
			$("#cleanBtn").attr("onclick","cleanIput()");
		}else {
			$("#cleanBtn > i").attr("class","icon-search");
			$("#cleanBtn ").attr("onclick","");
		}
	});
	/*清空输入框*/
	function cleanIput(){
		$("#SearchUserTxt").val("");
		$("#SearchUserTxt").focus();
		$("#cleanBtn > i").attr("class","icon-search");
		$("#cleanBtn ").attr("onclick","");
	}
</script>

</body>
</html>